<template>
	<view>
		<view class="mt-5" v-if="u_loadmore">
			<u-loadmore status="loading" icon-type="circle" />
		</view>
		<view v-else>
			<view class="rounded-20 m-2 pl-3  bg-white" >
				<view class="d-flex j-sb pr-2 py-3">
					<view class="">赠送消费者积分数</view>
					<view class="d-flex j-center a-center">
						<input type="digit" :placeholder="rest_detail.give_integral" v-model="give_integral" @input="give_integral_input" class="text-right" placeholder-class="d-flex j-end" />
					</view>
				</view>		
			</view>
			<view class="py-2 d-flex flex-column j-end mr-2">
				<view class="d-flex j-end font-sm">购买该商品时赠送消费积分数。</view>
			</view>
			<view class="rounded-20 m-2 pl-3  bg-white" >
				<view class="d-flex j-sb pr-2 py-3">
					<view class="">赠送等级积分数</view>
					<view class="d-flex j-center a-center">
						<input type="digit" :placeholder="rest_detail.rank_integral" v-model="rank_integral" @input="rank_integral_input"  class="text-right" placeholder-class="d-flex j-end" />
					</view>
				</view>		
			</view>
			<view class="py-2 d-flex flex-column j-end  mr-2">
				<view class="d-flex j-end font-sm">购买该商品时赠送等级积分数。</view>
			</view>
			<view class="rounded-20 m-2 pl-3  bg-white" >
				<view class="d-flex j-sb pr-2 py-3">
					<view class="">积分购买金额</view>
					<view class="d-flex j-center a-center">
						<input type="digit" :placeholder="rest_detail.integral" v-model="integral" @input="integral_input" class="text-right" placeholder-class="d-flex j-end" />
					</view>
				</view>		
			</view>
			<view class="py-2 d-flex flex-column j-end mr-2">
				<view class="d-flex j-end font-sm">购买该商品时最多可以使用积分的金额。</view>
			</view>
			<view class="bg-white py-2 w-100 position-fixed bottom-0 btn">
				<button type="warn" @click="preserve">保存</button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				rest_detail:"", // 详情
				give_integral:'', // 消费者积分数
				rank_integral:'', // 赠送等级积分数
				integral:'', // 积分购买金额
				goods_id:'', // 商品ID
				u_loadmore:true, // 加载中
			}
		},
		methods: {
			// 消费者 积分数
			give_integral_input(e){
				this.give_integral=e.detail.value
			},
			// 赠送等级积分数
			rank_integral_input(e){
				this.rank_integral=e.detail.value
			},
			// 积分购买金额
			integral_input(e){
				this.integral=e.detail.value
			},
			preserve(){
				this.$H.post("admin/merchant/goods/price/updateAll",{
					goods_id:this.goods_id,
					give_integral:this.give_integral,
					rank_integral:this.rank_integral,
					integral:this.integral,
					shop_price:this.rest_detail.shop_price.replace("￥",''),
					cost_price:this.rest_detail.cost_price.replace("￥",''),
					market_price:this.rest_detail.market_price.replace('￥','')
				}).then(res=>{
					uni.navigateBack({
						delta:1
					})
					var globalData = getApp().globalData.rest; //获取全局变量
					getApp().globalData.rest= '其他'; //修改全局变量
				})
				
			}
		},
		onLoad(e) {
			this.goods_id=e.goods_id
			this.$H.post("admin/merchant/goods/detail",{goods_id:e.goods_id}).then(res=>{
				this.rest_detail=res.data
				this.u_loadmore=false 
			})
		}
	}
</script>

<style>
	.btn /deep/ button{
		width: 85%;
		border-radius: 50upx;
		background: linear-gradient(to right,#F31E3E,#FB4F37);
	}
</style>
